.class public final Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;
.super Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;
.source "NmeaBluetoothDevice.kt"


# instance fields
.field private final DEFAULT_SPP_UUID:Ljava/util/UUID;

.field private final device:Landroid/bluetooth/BluetoothDevice;

.field private volatile disconnected:Z

.field private inputStream:Ljava/io/InputStream;

.field private socket:Landroid/bluetooth/BluetoothSocket;


# direct methods
.method public constructor <init>(Landroid/bluetooth/BluetoothDevice;)V
    .locals 1

    const-string v0, "device"

    invoke-static {p1, v0}, Lkotlin/jvm/internal/Intrinsics;->checkParameterIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V

    .line 12
    invoke-direct {p0}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;-><init>()V

    const-string v0, "00001101-0000-1000-8000-00805F9B34FB"

    .line 14
    invoke-static {v0}, Ljava/util/UUID;->fromString(Ljava/lang/String;)Ljava/util/UUID;

    move-result-object v0

    iput-object v0, p0, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;->DEFAULT_SPP_UUID:Ljava/util/UUID;

    .line 16
    iput-object p1, p0, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;->device:Landroid/bluetooth/BluetoothDevice;

    return-void
.end method

.method public static final synthetic access$changeStatus(Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;Llt/farmis/libraries/externalgps/providers/Status;)V
    .locals 0

    .line 12
    invoke-virtual {p0, p1}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;->changeStatus(Llt/farmis/libraries/externalgps/providers/Status;)V

    return-void
.end method

.method public static final synthetic access$getDisconnected$p(Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;)Z
    .locals 0

    .line 12
    iget-boolean p0, p0, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;->disconnected:Z

    return p0
.end method

.method public static final synthetic access$getInputStream$p(Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;)Ljava/io/InputStream;
    .locals 0

    .line 12
    iget-object p0, p0, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;->inputStream:Ljava/io/InputStream;

    return-object p0
.end method

.method public static final synthetic access$getSocket$p(Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;)Landroid/bluetooth/BluetoothSocket;
    .locals 0

    .line 12
    iget-object p0, p0, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;->socket:Landroid/bluetooth/BluetoothSocket;

    return-object p0
.end method

.method private final connectToSocket()Z
    .locals 2

    .line 46
    :try_start_0
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;->device:Landroid/bluetooth/BluetoothDevice;

    iget-object v1, p0, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;->DEFAULT_SPP_UUID:Ljava/util/UUID;

    invoke-virtual {v0, v1}, Landroid/bluetooth/BluetoothDevice;->createRfcommSocketToServiceRecord(Ljava/util/UUID;)Landroid/bluetooth/BluetoothSocket;

    move-result-object v0

    iput-object v0, p0, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;->socket:Landroid/bluetooth/BluetoothSocket;

    .line 47
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;->socket:Landroid/bluetooth/BluetoothSocket;

    if-eqz v0, :cond_0

    invoke-virtual {v0}, Landroid/bluetooth/BluetoothSocket;->connect()V

    .line 48
    :cond_0
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;->socket:Landroid/bluetooth/BluetoothSocket;

    if-eqz v0, :cond_1

    invoke-virtual {v0}, Landroid/bluetooth/BluetoothSocket;->getInputStream()Ljava/io/InputStream;

    move-result-object v0

    goto :goto_0

    :cond_1
    const/4 v0, 0x0

    :goto_0
    iput-object v0, p0, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;->inputStream:Ljava/io/InputStream;

    .line 50
    sget-object v0, Llt/farmis/libraries/externalgps/providers/Status;->CONNECTED:Llt/farmis/libraries/externalgps/providers/Status;

    invoke-virtual {p0, v0}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;->changeStatus(Llt/farmis/libraries/externalgps/providers/Status;)V

    .line 53
    new-instance v0, Ljava/lang/Thread;

    new-instance v1, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice$connectToSocket$1;

    invoke-direct {v1, p0}, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice$connectToSocket$1;-><init>(Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;)V

    invoke-direct {v0, v1}, Ljava/lang/Thread;-><init>(Ljava/lang/Runnable;)V

    .line 69
    invoke-virtual {v0}, Ljava/lang/Thread;->start()V
    :try_end_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_1
    .catch Ljava/lang/NullPointerException; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_1

    :catch_0
    move-exception v0

    .line 76
    invoke-virtual {v0}, Ljava/lang/NullPointerException;->printStackTrace()V

    .line 77
    iget-boolean v0, p0, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;->disconnected:Z

    if-nez v0, :cond_2

    sget-object v0, Llt/farmis/libraries/externalgps/providers/Status;->CONNECTING_FAILED:Llt/farmis/libraries/externalgps/providers/Status;

    invoke-virtual {p0, v0}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;->changeStatus(Llt/farmis/libraries/externalgps/providers/Status;)V

    :cond_2
    :goto_1
    const/4 v0, 0x1

    return v0

    :catch_1
    move-exception v0

    .line 72
    iget-boolean v1, p0, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;->disconnected:Z

    if-nez v1, :cond_3

    sget-object v1, Llt/farmis/libraries/externalgps/providers/Status;->CONNECTING_FAILED:Llt/farmis/libraries/externalgps/providers/Status;

    invoke-virtual {p0, v1}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;->changeStatus(Llt/farmis/libraries/externalgps/providers/Status;)V

    .line 73
    :cond_3
    invoke-virtual {v0}, Ljava/io/IOException;->printStackTrace()V

    const/4 v0, 0x0

    return v0
.end method


# virtual methods
.method public connect()Z
    .locals 1

    const/4 v0, 0x0

    .line 25
    iput-boolean v0, p0, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;->disconnected:Z

    .line 26
    sget-object v0, Llt/farmis/libraries/externalgps/providers/Status;->CONNECTING:Llt/farmis/libraries/externalgps/providers/Status;

    invoke-virtual {p0, v0}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;->changeStatus(Llt/farmis/libraries/externalgps/providers/Status;)V

    .line 27
    invoke-direct {p0}, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;->connectToSocket()Z

    move-result v0

    return v0
.end method

.method public disconnect()V
    .locals 2

    const/4 v0, 0x1

    .line 31
    iput-boolean v0, p0, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;->disconnected:Z

    .line 32
    sget-object v0, Llt/farmis/libraries/externalgps/providers/Status;->DISCONNECTED:Llt/farmis/libraries/externalgps/providers/Status;

    invoke-virtual {p0, v0}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;->changeStatus(Llt/farmis/libraries/externalgps/providers/Status;)V

    .line 34
    :try_start_0
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;->socket:Landroid/bluetooth/BluetoothSocket;

    if-eqz v0, :cond_0

    invoke-virtual {v0}, Landroid/bluetooth/BluetoothSocket;->close()V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_0

    :catch_0
    move-exception v0

    .line 36
    invoke-virtual {v0}, Ljava/lang/Exception;->getMessage()Ljava/lang/String;

    move-result-object v0

    const-string v1, "NMEA_CLOSE_EXCEPTION"

    invoke-static {v1, v0}, Landroid/util/Log;->i(Ljava/lang/String;Ljava/lang/String;)I

    :cond_0
    :goto_0
    return-void
.end method

.method public final getConnectedDevice()Landroid/bluetooth/BluetoothDevice;
    .locals 1

    .line 82
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/bluetooth/NmeaBluetoothDevice;->device:Landroid/bluetooth/BluetoothDevice;

    return-object v0
.end method
